﻿@{
    ViewBag.Title = "ProjectTaskBookList";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@using Common.BaseLibrary.Authorization
@using DepartmentWork.Model
@model List<DepartmentWork.Model.ProjectTaskBookViewModel>


<div class="page-header">
    <div class="pull-left">
        <ol class="breadcrumb visible-sm visible-md visible-lg">
            <li><a href="@Url.Action("Index","Home",new{area=""})"><i class="icon fa fa-home"></i>主页</a></li>
            <li><a href="@Url.Action("Index","Project",new{area="DevelopArea"})"><i class="fa fa-envelope"></i>开发模块</a></li>
            <li><a href="@Url.Action("ProjectInfo","Project",new{area="DevelopArea",projectId=ViewBag.ProjectId})"><i class="fa fa-envelope"></i>项目详情</a></li>
            <li class="active"><a href="#"><i class="fa fa-envelope"></i>任务书</a></li>
        </ol>
    </div>
</div>

@{
    if (ViewBag.Flag == "CreateTrue")
    {
    <div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong>&emsp;任务书添加成功！</strong>
    </div>
    }
    if (ViewBag.Flag == "CreateFalse")
    {
      <div class="alert alert-danger">
	    <button type="button" class="close" data-dismiss="alert">×</button>
	    <strong>&emsp;任务书添加失败！</strong> @ViewBag.Info
    </div>
    }
    
    if (ViewBag.Flag == "EditTrue")
    {
    <div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong>&emsp;任务书编辑成功！</strong>
    </div>
    }
    if (ViewBag.Flag == "EditFalse")
    {
      <div class="alert alert-danger">
	    <button type="button" class="close" data-dismiss="alert">×</button>
	    <strong>&emsp;任务书辑失败！</strong> @ViewBag.Info
    </div>
    }
    
    if (ViewBag.Flag == "DelTrue")
    {
    <div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">×</button>
        <strong>&emsp;任务书删除成功！</strong>
    </div>
    }
    if (ViewBag.Flag == "DelFalse")
        {
      <div class="alert alert-danger">
	    <button type="button" class="close" data-dismiss="alert">×</button>
	    <strong>&emsp;任务书删除失败！</strong> @ViewBag.Info
    </div>
        }
    
}


<script>

    function DelTaskBook(taskBookId)
    {
        if (!confirm("请确认是否删除该任务书？"))
        {
            return false;
        }
        window.location.href = '@Url.Action("DeleteTaskBook","TaskBook",new{area="DevelopArea"})' + '?taskBookId=' + taskBookId;
    }

</script>
<div class="row">
    <div class="col-lg-12">
        <div class="panel">
            <div class="panel-heading bk-bg-primary">
                <h6><i class="fa fa-table red"></i><span style="font-size: medium" class="break">@ViewBag.ProjectName 项目的 任务书</span></h6>
                                
               @{
                    if (ViewBag.IsDevelopLeader==true)
                    {
                        <div class="panel-actions">
                            <a data-toggle="modal" data-target="#TaskBookCreateModal" class="bk-margin-5 btn btn-default  btn-sm" style="background-color: #ECEDF0">&nbsp;&nbsp;新增任务书&nbsp;&nbsp;</a>
                        </div>                    
                    }
                }



            </div>
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>任务书名称</th>
                                <th>创建人</th>
                                <th>创建时间</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>

                            @for (int i = 0; i < this.Model.Count(); i++)
                            {
                                var item = this.Model[i];
                                <tr>
                                    <td style="color:cornflowerblue" data-toggle="modal" onclick="ShowTaskBookInfoModal('@item.TaskBookId')" data-target="#TaskBookInfoModal">
                                        <b> @item.TaskBookName</b>
                                    </td>
                                    <td>@item.Creater</td>
                                    <td>@item.TaskBookCreateTime</td>
                                    <td>
                                        @{
                                            if (ViewBag.IsDevelopLeader == true)
                                            {
                                                <a  style="color:cornflowerblue" data-toggle="modal" onclick="ShowTaskBookEditModal('@item.TaskBookId')" data-target="#TaskBookEditModal">编辑</a>
                                                @:&nbsp; &nbsp; &nbsp; 
                                                <a  style="color:cornflowerblue" class="a_DeleteTaskBook" onclick="DelTaskBook('@item.TaskBookId')" >删除</a>
                                            }
                                        }
                                    </td>
                                </tr>
                            }


                        </tbody>
                    </table>
                    <div class="bk-margin-5 btn-group" style="float: right">
                          @Html.ShowPageNavigate((int)ViewData["pageIndex"], (int)ViewData["pageSize"], (int)ViewData["total"],(string)ViewBag.ProjectId)
                     </div>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    function ShowTaskBookInfoModal(taskBookId)
    {
        $.ajax({
            type: "POST",
            //url: "/KSManager/DevelopArea/TaskBook/GetTaskBookInfo",
            url:'@Url.Action("GetTaskBookInfo","TaskBook",new{area="DevelopArea"})',
            data: "taskBookId=" + taskBookId,
            error: function () { alert("服务器出错！"); },
            success: function (data)
            {
                // $("#TaskBookInfoModal").attr("aria-hidden", "true");
                $("#lb_TaskBookInfo_Name").text(data["TaskBookName"]);
                $("#lb_TaskBookInfo_Creater").text(data["Creater"]);
                
                var content = "";
                for (var i = 0; i < data["TaskBookContext"].length; i++)
                {
                    if (i % 35 == 0 && i != 0)
                    {
                        content += data["TaskBookContext"][i] + "<br/>";
                    } else
                    {
                        content += data["TaskBookContext"][i];
                    }

                }
                $("#lb_TaskBookInfo_Context").html(content);


                $("#lb_TaskBookInfo_CreateTime").text(data["TaskBookCreateTime"]);

                if (data["TaskBookFileSaveName"] == "")
                {
                    //$("#lb_TaskBookInfo_File").text("");
                    $("#a_DownloadTaskBookFile").text("");
                } else
                {
                    //$("#lb_TaskBookInfo_File").text(data["TaskBookFileShowName"]);
                    $("#a_DownloadTaskBookFile").text(data["TaskBookFileShowName"]);
                    //$("#a_DownloadTaskBookFile").attr("href", "http:////" + data["TaskBookFilePath"] + '//' + data["TaskBookFileSaveName"]);
                    $("#a_DownloadTaskBookFile").attr("href", '@Url.Content("~/Home/DownLoadFile?filePath=")' + data["TaskBookFileSaveName"] + "&type=TaskBook&fileName=" + data["TaskBookFileSaveName"]);

                }

            }
        });
    }

</script>


<!-- 任务书详情 模态框（Modal） -->

<div class="modal fade" id="TaskBookInfoModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">任务书详情
                </h4>
            </div>
            <div class="modal-body" style="font-size: small">
                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">任务书名称：</label>
                    <div class="col-md-9">
                        <label id="lb_TaskBookInfo_Name" style="width:100%" class="col-md-3 control-label" for="text-input"></label>
                    </div>
                </div>
                <hr />

                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">创建人：</label>
                    <div class="col-md-9">
                        <label id="lb_TaskBookInfo_Creater" style="width:100%"  class="col-md-8 control-label" for="text-input"></label>
                    </div>
                </div>
                <hr />

                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">任务书详情：</label>
                    <div class="col-md-9">
                        <label id="lb_TaskBookInfo_Context" style="width:100%"  class="col-md-8 control-label" for="text-input"></label>
                    </div>
                </div>

                <hr />

                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">任务书创建时间：</label>
                    <div class="col-md-9">
                        <label id="lb_TaskBookInfo_CreateTime" style="width:100%"  class="col-md-8 control-label" for="text-input"></label>
                    </div>
                </div>

                <hr />

                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">任务书附件：</label>
                    <div class="col-md-9">
                        <a  style="color:cornflowerblue" id="a_DownloadTaskBookFile">
                            
                        </a>
                    </div>
                </div>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>




<script>
    function ShowTaskBookEditModal(taskBookId) {
        $("#hid_EditTaskBookId").val(taskBookId);
        $.ajax({
            type: "POST",
            //url: "/KSManager/DevelopArea/TaskBook/GetTaskBookInfo",
            url:'@Url.Action("GetTaskBookInfo","TaskBook",new{area="DevelopArea"})',
            data: "taskBookId=" + taskBookId,
            error: function () { alert("服务器出错！"); },
            success: function (data)
            {
                // $("#TaskBookInfoModal").attr("aria-hidden", "true");
                $("#tb_TaskBookName").val(data["TaskBookName"]);
                $("#tb_Creater").val(data["Creater"]);
                $("#tb_TaskBookContext").text(data["TaskBookContext"]);
                $("#tb_CreateTime").val(data["TaskBookCreateTime"]);

                if (data["TaskBookFileSaveName"] == "")
                {
                    //$("#lb_TaskBookFile").text("");
                    $("#a_EditDownloadTaskBookFile").text("");
                } else
                {
                    //$("#lb_TaskBookFile").text(data["TaskBookFileShowName"]);
                    $("#a_EditDownloadTaskBookFile").text(data["TaskBookFileShowName"]);
                    //$("#a_DownloadTaskBookFile").attr("href", "http:////" + data["TaskBookFilePath"] + '//' + data["TaskBookFileSaveName"]);
                    $("#a_EditDownloadTaskBookFile").attr("href", '@Url.Content("~/Home/DownLoadFile?filePath=")' + data["TaskBookFileSaveName"] + "&type=TaskBook&fileName=" + data["TaskBookFileShowName"]);

                }

            }
        });
    }

</script>

<!-- 编辑任务书 模态框（Modal） -->

<div class="modal fade" id="TaskBookEditModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">编辑任务书
                </h4>
            </div>
            <form enctype="multipart/form-data" action="@Url.Action("EditTaskBook", "TaskBook", new { area = "DevelopArea" })" method="POST" >
            <div class="modal-body">
                <input type="hidden" name="hid_EditTaskBookId" id="hid_EditTaskBookId"/>
                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">任务书名称：</label>
                    <div class="col-md-9">
                        <input id="tb_TaskBookName" style="border-color: cornflowerblue" name="tb_TaskBookName" class="form-control" placeholder="Text" type="text">
                    </div>
                </div>
                <br />

                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">任务书创建人：</label>
                    <div class="col-md-9">
                        <input id="tb_Creater" disabled="disabled" style="border-color: cornflowerblue" name="tb_Creater" class="form-control" placeholder="Text" type="text">
                    </div>
                </div>
                <br />

                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">任务书详情：</label>
                    <div class="col-md-9">
                        <textarea id="tb_TaskBookContext" name="tb_TaskBookContext" class="form-control" rows="3"></textarea>
                    </div>
                </div>
                <br />
                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">任务书创建时间：</label>
                    <div class="col-md-9">
                        <input id="tb_CreateTime" disabled="disabled" style="border-color: cornflowerblue" name="tb_CreateTime" class="form-control" placeholder="Text" type="text">
                    </div>
                </div>
                <br />
                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">原附件：</label>
                    <div class="col-md-9"> 
                        <a id="a_EditDownloadTaskBookFile" style="color:cornflowerblue">
                            
                        </a>
                    </div>
                </div>
                <br />

                <div class="row">
                    <label class="col-md-3 control-label" for="text-input">附件：</label>
                    <div class="col-md-9">
                        <input id="tb_TaskBookFile" style="border-color: cornflowerblue" name="tb_TaskBookFile" class="form-control" placeholder="Text" type="file">
                    </div>
                </div>
                <br />

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
                <input type="submit" value="提交更改" class="btn btn-primary"/>
            </div>
            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>

<!-- 新增任务书 模态框（Modal） -->

<div class="modal fade" id="TaskBookCreateModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">新增任务书
                </h4>
            </div>
            <form id="frm_CreateTaskBook" enctype="multipart/form-data" action="@Url.Action("CreateTaskBook", "TaskBook", new { area = "DevelopArea" })" method="POST" >

                <div class="modal-body">
                    <div class="alert alert-danger" id="div_CheckCreateTaskBookMessage" style="display:none">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong><label id="lb_CheckCreateTaskBookMessage"></label></strong>
                    </div>
                    <input  type="hidden" value="@ViewBag.ProjectId" name="hid_ProjectId"/>
                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">任务书名称：</label>
                        <div class="col-md-9">
                            <input name="tb_TaskBookName" id="tb_CreateTaskBookName" style="border-color: cornflowerblue" class="form-control" placeholder="Text" type="text">
                        </div>
                    </div>
                    <br />

                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">任务书创建人：</label>
                        <div class="col-md-9">
                            <input name="tb_TaskBookCreater"id="tb_CreateTaskBookCreater" value="@CurrentUser.UserName" disabled="disabled" style="border-color: cornflowerblue"  class="form-control" placeholder="Text" type="text">
                        </div>
                    </div>
                    <br />

                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">任务书详情：</label>
                        <div class="col-md-9">
                            <textarea name="tb_TaskBookContext" id="tb_CreateTaskBookContext" class="form-control" rows="3"></textarea>
                        </div>
                    </div>
                    <br />

                    <div class="row">
                        <label class="col-md-3 control-label" for="text-input">附件：</label>
                        <div class="col-md-9">
                            <input name="tb_TaskBookFile" id="tb_CreateTaskBookFile" style="border-color: cornflowerblue" class="form-control" placeholder="Text" type="file">
                        </div>
                    </div>
                    <br />

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">
                        关闭
                    </button>
                    <input type="button" onclick="SubmitCreate()" value="新增" class="btn btn-primary" />
                </div>

            </form>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>

<script>
    function SubmitCreate()
    {
        var message = "";
        if ($("#tb_CreateTaskBookName").val() == "" || $.trim($("#tb_CreateTaskBookName").val()) == "")
        {
            message += " · 任务书名称不能为空" + "<br/>";
        }
        if ($("#tb_CreateTaskBookContext").val() == "")
        {
            message += " · 任务书详情不能为空" + "<br/>";
        }
        if (message != "")
        {
            $("#lb_CheckCreateTaskBookMessage").html(message);
            $("#div_CheckCreateTaskBookMessage").css("display", "block");
            return false;
        }
        else
        {
            $("#lb_CheckCreateTaskBookMessage").html("");
            $("#div_CheckCreateTaskBookMessage").css("display", "none");
            $("#frm_CreateTaskBook").submit();
        }
    }
</script>
